<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<title></title> <jsp:include page="../common/head.jsp"></jsp:include>


<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}

@media ( max-width : 980px) {
	/* Enable use of floated navbar text */
	.navbar-text.pull-right {
		float: none;
		padding-left: 5px;
		padding-right: 5px;
	}
}

tr {
	cursor: pointer;
}
</style>
</head>
<body>
	<div class="definewidth">
		<shiro:hasPermission name="sys:perm:add">
			 <a class="btn btn-success"
				href="${path}/resources/add">新增菜单</a>
		</shiro:hasPermission>
	</div>
	<table class="table table-bordered table-hover definewidth m10">
		<thead>
			<tr>
				<th>菜单标题</th>
				<th>菜单类型</th>
				<th>描述</th>
				<th>菜单编码</th>
				<th>url</th>
				<th>是否启用</th>
				<th>操作</th>
			</tr>
		</thead>
		<c:forEach items="${list}" var="u">
			<c:if test="${u.pid==0 }">
			<tr pid="${u.pid}" ids="${u.id}">
				<td colspan="6">${u.name}</td>
				<td>
					<shiro:hasPermission name="sys:perm:update">
					 <a class="edit" href="${path}/resources/add?id=${u.id}">修改</a>
					</shiro:hasPermission>
				</td>
			</tr>
			</c:if>
			<c:forEach items="${list }" var="r">
				<c:if test="${ r.pid==u.id && r.type==0}">
					<tr pid="${r.pid}" ids="${r.id}">
						<td style="padding-left: 30px;">${r.name}</td>
						<td>
							<c:if test="${r.type==0 }">菜单</c:if>
							<c:if test="${r.type != 0 }">按钮</c:if>
						</td>
						<td>${r.description}</td>
						<td>${r.permission}</td>
						<td>${r.url}</td>
						<td>
							<c:if test="${r.disabled==0 }">启用</c:if>
							<c:if test="${r.disabled != 0 }">禁用</c:if>
						</td>
						<td>
							<shiro:hasPermission name="sys:perm:update">
							 <a class="edit" href="${path}/resources/add?id=${r.id}">修改</a>
							</shiro:hasPermission>
						</td>
					</tr>
					<c:forEach items="${list }" var="rr">
						<c:if test="${rr.pid==r.id }">
							<tr pid="${rr.pid}" ids="${rr.id}" rid="${u.id}">
							<td style="padding-left: 50px;">${rr.name}</td>
							<td>
								<c:if test="${rr.type==0 }">菜单</c:if>
								<c:if test="${rr.type != 0 }">按钮</c:if>
							</td>
							<td>${rr.description}</td>
							<td>${rr.permission}</td>
							<td>${rr.url}</td>
							<td>
								<c:if test="${rr.disabled==0 }">启用</c:if>
								<c:if test="${rr.disabled != 0 }">禁用</c:if>
							</td>
							<td><shiro:hasPermission name="sys:perm:update"> 
									<a class="edit" href="${path}/resources/add?id=${rr.id}">修改</a>
								</shiro:hasPermission>
							</td>
						</tr>
						</c:if>
					</c:forEach>
				</c:if>
			</c:forEach>
		</c:forEach>
	</table>
	<jsp:include page="../common/foot.jsp"></jsp:include>
	<script type="text/javascript">
		$("[pid]").click(function() {
			var pid = $(this).attr("pid");
			var ids = $(this).attr("ids");
			var flag = $(this).attr("flag");
			if (flag == 1) {
				$(this).removeAttr("flag");
				$("[pid='" + ids + "']").show().removeAttr("flag");
				$("[rid='" + ids + "']").show();
			} else {
				$(this).attr("flag", "1");
				$("[pid='" + ids + "']").hide().attr("flag", "1");
				$("[rid='" + ids + "']").hide();
			}
		});
	</script>
</body>
</html>
